package com.baymax.test.scene.life;

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.baymax.test.scene.MainActivity
import com.baymax.test.scene.ProjectTestScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.helper.setupSceneAnonymous
import com.baymax.test.scene.internal.BackGround
import com.baymax.test.scene.newFlexContainer

class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setContentView(btn)
        val nav = this.setupSceneAnonymous()
        findViewById<ViewGroup>(android.R.id.content).newFlexContainer {
            addButton("toMain newTask") {
                toAc(MainActivity::class.java)
            }

            addButton("toSEC newTask") {
                toAc(SecondActivity::class.java)
            }

            addButton("toMain") {
                toAc(MainActivity::class.java, false)
            }

            addButton("toSEC") {
                toAc(SecondActivity::class.java ,false)
            }
            addButton("start background service"){
                val serIntent = Intent(context, BackGround::class.java)
                ContextCompat.startForegroundService(context, serIntent)
            }
        }


        //postMessage(btn)
    }


    fun toAc(clazz: Class<*>, newTask: Boolean = true) {
        startActivity(Intent(applicationContext, clazz).apply {
            if (newTask) {
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
        })
    }


}
